from django.contrib import admin
from .models import CameraCategory, CameraEntry, AccessoryCategory, CameraAccessory

@admin.register(CameraCategory)
class CameraCategoryAdmin(admin.ModelAdmin):
    list_display = ('name', 'created_at')
    search_fields = ('name',)
    list_filter = ('created_at',)

@admin.register(CameraEntry)
class CameraEntryAdmin(admin.ModelAdmin):
    list_display = ('title', 'brand', 'category', 'created_at', 'updated_at')
    search_fields = ('title', 'brand', 'content')
    list_filter = ('category', 'brand', 'created_at')
    date_hierarchy = 'created_at'
    fieldsets = (
        ('基本信息', {
            'fields': ('title', 'brand', 'category')
        }),
        ('详细规格', {
            'fields': ('release_date', 'sensor_type', 'image_resolution')
        }),
        ('内容', {
            'fields': ('content',)
        })
    )

@admin.register(AccessoryCategory)
class AccessoryCategoryAdmin(admin.ModelAdmin):
    list_display = ('name', 'created_at')
    search_fields = ('name',)
    list_filter = ('created_at',)

@admin.register(CameraAccessory)
class CameraAccessoryAdmin(admin.ModelAdmin):
    list_display = ('title', 'brand', 'category', 'created_at', 'updated_at')
    search_fields = ('title', 'brand', 'content')
    list_filter = ('category', 'brand', 'created_at')
    date_hierarchy = 'created_at'
    filter_horizontal = ('compatible_cameras',)
    fieldsets = (
        ('基本信息', {
            'fields': ('title', 'brand', 'category')
        }),
        ('规格信息', {
            'fields': ('price_range', 'compatible_cameras')
        }),
        ('内容', {
            'fields': ('content',)
        })
    )
